package bcxd.firstline.credit.machining;

import java.sql.Connection;
import java.util.Map;

import org.limp.basework.MachiningException;
import org.limp.basework.SimpleBean;
import org.limp.basework.SimpleBean4Table;
import org.limp.basework.SimpleBeanMachining;
import org.limp.basework.Table;
import org.limp.basework.impl.CommonBean4HSQ;
import org.limp.basework.impl.SimpleBean4TableImpl;
import org.limp.basework.tools.BaseworkUtil;
import org.limp.mine.DateTrimmer;
import org.limp.mine.EncryptTool;
import org.limp.mine.RandomUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ApplyMachining implements SimpleBeanMachining {

	private static final Logger LOG = LoggerFactory
			.getLogger(ApplyMachining.class);

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public SimpleBean machining(SimpleBean bean, Table table,
			CommonBean4HSQ request, Connection conn, int type)
			throws MachiningException {

		LOG.debug("type={}", type);

		if (type == -4) {
			String status = "0";

			Map apply = bean.getResource();
			apply.put("cr_audit_status", status);
			apply.put("cr_apply_date", DateTrimmer.getYMDHMS());

			SimpleBean4Table user = new SimpleBean4TableImpl("BCXD_USER");
			user.getResource().put("uname", apply.get("cr_name"));
			user.getResource().put("logid", RandomUtil.getRandomString(10));
			user.getResource().put("pwd", EncryptTool.encryptString("000000"));
			user.getResource().put("utype", "creditproviders");
			user.getResource().put("ustatus", status);

			try {
				new BaseworkUtil().manualSave1(user, conn);
			} catch (Exception e) {
				throw new MachiningException("create creditproviders user error.", e);
			}
		}
		return null;
	}

}
